<div class="da-list-wrap">
  <div class="da-content-banner">
    <d-breadcrumb>
      <d-breadcrumb-item><a routerLink="/">{{ 'basicdata.breadcrumb.home' | translate }}</a></d-breadcrumb-item>
      <d-breadcrumb-item>采购需求单</d-breadcrumb-item>
    </d-breadcrumb>
  </div>
  <div class="da-content-wrapper">
    <d-splitter orientation="vertical" disabledBarSize="1px" [splitBarSize]="splitBarSize" style="height: 100%"
      [showCollapseButton]="true">
      <d-splitter-pane minSize="50%" [size]="partDetailHeight">
        <div class="da-list-container">
          <div class="da-list-header">
            <div class="d-input">
              <div class="inputIn">
                <input dTextInput style="width: 180px;" [error]="false" placeholder="采购需求单" name="采购需求单编码"
                  [(ngModel)]="fifter.PurchaseRequiredNum">
                <d-range-datepicker-pro name="制单日期" [placeholder]="['制单日期：起始','制单日期：截止']" [(ngModel)]="date"
                  (ngModelChange)="dateChange($event)"></d-range-datepicker-pro>
                <input dTextInput style="width: 180px;" [error]="false" placeholder="物料编码/物料名称" name="物料编码/物料名称"
                  [(ngModel)]="fifter.PartNumPartName">
                <input dTextInput style="width: 180px;" [error]="false" placeholder="申请人编码/申请人名称" name="申请人编码/申请人名称"
                  [(ngModel)]="fifter.PurchaseManNumPurchaseManName">
                <d-select [placeholder]="'单据状态'" name='单据状态' [(ngModel)]="fifter.Status" [options]="status"></d-select>
              </div>
              <div class="d-submit">
                <d-button id="primaryBtn" style="margin-left: 8px" (btnClick)="filter2()"><i
                    class="icon icon-filter-o me-2"></i>查询</d-button>
                <d-button bsStyle="common" (btnClick)="reset()"> <i class="icon icon-refresh me-2"></i>重置</d-button>
              </div>
            </div>
            <div class="btn-group">
              <div class="btn-left">
                <d-button bsstyle="primaryBtn" (click)="creat()"> <i class="icon icon-add me-2"></i>新增</d-button>
                <d-button bsStyle="danger" (btnClick)="delete()"> <i class="icon icon-code-editor-close me-2"></i>删除
                </d-button>
                <d-button bsStyle="common" (btnClick)="launchReview()"><span class="me-2">发起审核</span></d-button>
                <d-button bsStyle="common"><span class="me-2">反审核</span></d-button>
                <d-button bsStyle="common" (btnClick)="ClosePurchaseRequiredOrder(true)"> <i
                    class="icon icon-solved me-2"></i>结案</d-button>
                <d-button bsStyle="common" (btnClick)="ClosePurchaseRequiredOrder(false)"> <i
                    class="icon icon-infomation me-2"></i>反结案</d-button>
                <d-button bsStyle="common" (btnClick)="printSelected()"> <i class="icon icon-print me-2"></i>打印</d-button>
                <!-- <div dDropDown style="display: inline-block;">
                  <input type="file" #fileInput2 style="display: none" (change)="import($event)">
                  <d-button-group>
                    <d-button bsStyle="common" dDropDownToggle (btnClick)="onButtonClick()"><span
                        class="me-2">导入</span><span class="icon-chevron-down-2 "></span></d-button>
                  </d-button-group>
                  <ul dDropDownMenu class="devui-dropdown-menu" role="menu">
                    <li role="menuitem" (click)="downloadTemplate()">
                      <a dDropDownMenuItem>下载模板</a>
                    </li>
                  </ul>
                </div>
                <d-button bsStyle="common" (btnClick)="download()"> <i class="icon icon-related me-2"></i>导出</d-button> -->
                <d-button bsStyle="common" (btnClick)="allLog()">日志</d-button>
              </div>
            </div>
          </div>
          <div class="list-content">
            <d-data-table [dataSource]="tableData" [lazy]="true" [scrollable]="true" [fixHeader]="true"
              [tableWidthConfig]="tableWidthConfig" [tableOverflowType]="'auto'" [scrollable]="true"
              (checkAllChange)="getCheckedRows();getCheckedRowsData() "
              (rowCheckChange)="getCheckedRows();getCheckedRowsData()" [resizeable]="true">
              <thead dTableHead [checkable]="true">
                <tr dTableRow>
                  <th dHeadCell [fixedRight]="colOption.fixedRight" [fixedLeft]="colOption.fixedLeft"
                    *ngFor="let colOption of dataTableOptions.columns">{{ colOption.header }}</th>
                </tr>
              </thead>
              <tbody dTableBody>
                <ng-template let-rowItem="rowItem" let-rowIndex="rowIndex" let-nestedIndex="nestedIndex">
                  <tr dTableRow (click)="showDetail(rowItem, rowIndex)"
                    [ngClass]="{'selected-row': rowIndex === selectedRowIndex}">
                    <td dTableCell [fixedLeft]="'0px'">
                      <d-checkbox [disabled]="false" [showAnimation]="true" [ngModelOptions]="{ standalone: true }"
                        [ngModel]="rowItem.$checked" dTooltip [halfchecked]="rowItem.$halfChecked"
                        [showGlowStyle]="false"
                        (ngModelChange)="onRowCheckChange($event, rowIndex, nestedIndex, rowItem)"></d-checkbox>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [fixedLeft]="'80px'">
                      <span><a class="devui-link ms-3"
                          (click)="clickCode(rowItem.purchaseRequiredNum,'采购需求单审核',rowItem.status)" [class.disabled]="rowItem.status=='未开始审核'">审核</a></span>
                      <span><a class="devui-link ms-3" [class.disabled]="rowItem.status !== '未开始审核'"
                          (click)="edit(rowItem.purchaseRequiredOrderId)">编辑</a>
                      </span>
                      <span class="ms-3"><a class="devui-link-danger"
                          (click)="delete(rowItem.purchaseRequiredOrderId)">删除</a>
                      </span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'" [fixedLeft]="'430px'">
                      <span dTooltip [content]="rowItem?.purchaseRequiredNum">{{rowItem?.purchaseRequiredNum}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span dTooltip
                        [content]="rowItem.purchaseManNum + ' / ' + rowItem.purchaseManName">{{rowItem?.purchaseManName}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span dTooltip
                        [content]="rowItem.departmentNum + ' / ' + rowItem.departmentName">{{rowItem.departmentName}}</span>
                    </td>

                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span dTooltip
                        [content]="rowItem.advicePurchaseDate | date:'yyyy-MM-dd'">{{rowItem.advicePurchaseDate | date:'yyyy-MM-dd'}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span>
                        <d-tag [tag]="rowItem?.isClosed | booleanToText: '已结案':'未结案'" [labelStyle]="rowItem?.isClosed">
                        </d-tag>
                      </span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span dTooltip [content]="rowItem.remark">{{rowItem.remark}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span (click)="fujian(rowItem)"><a class="devui-link">附件</a></span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span>
                        <div dImagePreview>
                          <d-badge *ngIf="rowItem.qrCodePath" [count]="getImagesArray2(rowItem.qrCodePath).length" status="success">
                            <ng-container *ngFor="let imageUrl of getImagesArray2(rowItem.qrCodePath); let i = index">
                              <img *ngIf="getImagesArray2(rowItem.qrCodePath).length > 0" [src]="imageUrl" alt="图片" height="22px" [ngStyle]="{'display': i === 0 ? 'block' : 'none'}" />
                            </ng-container>
                          </d-badge>
                        </div>
                      </span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span dTooltip [content]="rowItem.creator">{{rowItem.creator}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span dTooltip
                        [content]="rowItem.createDate | date:'yyyy-MM-dd HH:mm:ss'">{{rowItem.createDate | date:'yyyy-MM-dd HH:mm:ss'}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span class="" (click)="GetLogsById(rowItem.purchaseRequiredOrderId)"><a
                          class="devui-link">日志</a></span>
                    </td>
                    <td dTableCell [fixedRight]="'0px'" [rowItem]="rowItem" [field]="'showType'">
                      <span>
                        <d-tag [tag]="rowItem?.status" [labelStyle]="rowItem?.status"></d-tag>
                      </span>
                    </td>
                  </tr>
                </ng-template>
              </tbody>
            </d-data-table>
          </div>
          <div class="page-footer">
            <div>
              <p>已选 <span class="underline">{{checkedIds.length}}</span> 条
                <a (click)="cleared()" class="cleared">清空</a>
              </p>
            </div>
            <d-pagination [size]="'sm'" [canViewTotal]="true" [canChangePageSize]="true" [canJumpPage]="true"
              [maxItems]="5" [total]="this.pager.total" [pageSizeOptions]="this.pageSizeOptions"
              [(pageSize)]="fifter.PageSize" [(pageIndex)]="fifter.PageNumber"
              (pageIndexChange)="pageIndexChange($event)" (pageSizeChange)="pageSizeChange($event)">
            </d-pagination>
          </div>
        </div>
      </d-splitter-pane>
      <d-splitter-pane class="detailTable" style="overflow: hidden;" [collapsible]="true">
        <div class="da-list-container">
          <div class="list-content">
            <d-data-table [dataSource]="partDetail" [lazy]="true" [scrollable]="true" [fixHeader]="true"
              [scrollable]="true" [resizeable]="true" [tableWidthConfig]="tableWidthConfig2">
              <thead dTableHead>
                <tr dTableRow>
                  <th dHeadCell>
                    <span><span class="Required">*</span>操作</span>
                  </th>
                  <th dHeadCell>
                    <span><span class="Required">*</span>物料编码</span>
                  </th>
                  <th dHeadCell>
                    <span>图片</span>
                  </th>
                  <th dHeadCell>
                    <span>物料名称</span>
                  </th>
                  <th dHeadCell>
                    <span>规格型号</span>
                  </th>
                  <th dHeadCell>
                    <span>是否结案</span>
                  </th>
                  <th dHeadCell>
                    <span>物料描述</span>
                  </th>
                  <th dHeadCell>
                    <span>单位</span>
                  </th>
                  <th dHeadCell>
                    <span><span class="Required">*</span>申请采购数量</span>
                  </th>
                  <th dHeadCell>
                    <span><span class="Required">*</span>建议采购时间</span>
                  </th>
                  <th dHeadCell>
                    <span><span class="Required">*</span>已订数量</span>
                  </th>
                  <th dHeadCell>
                    <span>建议供应商</span>
                  </th>
                  <th dHeadCell>
                    <span>是否检验</span>
                  </th>
                  <th dHeadCell>
                    <span>备注</span>
                  </th>
                </tr>
              </thead>
              <tbody dTableBody>
                <ng-template let-rowItem="rowItem" let-rowIndex="rowIndex">
                  <tr dTableRow>
                    <td dTableCell>
                      <span><a class="devui-link" [class.disabled]="rowItem?.isClosed"
                          (click)="ClosePurchaseRequiredOrderPart(rowItem, true)">结案</a></span>
                      <span class="ms-3"><a [class.disabled]="!rowItem?.isClosed"
                          (click)="ClosePurchaseRequiredOrderPart(rowItem, false)" class="devui-link">反结案</a></span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.partNum">{{rowItem.partNum}}</span>
                    </td>
                    <td dTableCell>
                      <span>
                        <div dImagePreview>
                          <d-badge *ngIf="rowItem.image" [count]="getImagesArray(rowItem.image).length"
                            status="success">
                            <ng-container *ngFor="let imageUrl of getImagesArray(rowItem.image); let i = index">
                              <img *ngIf="getImagesArray(rowItem.image).length > 0" [src]="imageUrl" alt="图片"
                                height="22px" [ngStyle]="{'display': i === 0 ? 'block' : 'none'}" />
                            </ng-container>
                          </d-badge>
                        </div>
                      </span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.partName">{{rowItem.partName}}</span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.partType">{{rowItem.partType}}</span>
                    </td>
                    <td dTableCell [rowItem]="rowItem" [field]="'showType'">
                      <span>
                        <d-tag [tag]="rowItem?.isClosed | booleanToText: '已结案':'未结案'"
                          [labelStyle]="rowItem?.isClosed === true ? 'true' : 'false'">
                        </d-tag>
                      </span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.description">{{rowItem.description}}</span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.partUOM">{{rowItem.partUOM}}</span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.purchaseQuantity">{{rowItem.purchaseQuantity}}</span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.purchaseDate">{{rowItem.purchaseDate}}</span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.orderedQuantity">{{rowItem.orderedQuantity}}</span>
                    </td>
                    <td dTableCell>
                      <input dTextInput [ngModelOptions]="{standalone: true}" [(ngModel)]="rowItem.supplyName"  (click)="selectsupply(rowItem)"/>
                    </td>
                    <td dTableCell>
                      <span>
                        <d-tag [tag]="rowItem?.isInspection | booleanToText: '检验':'不检验'"
                          [labelStyle]="rowItem?.isInspection === true ? '检验' : '不检验'">
                        </d-tag>
                      </span>
                    </td>
                    <td dTableCell>
                      <span dTooltip [content]="rowItem.remark">{{rowItem.remark}}</span>
                    </td>
                  </tr>
                </ng-template>
              </tbody>
            </d-data-table>
          </div>
        </div>
      </d-splitter-pane>
    </d-splitter>
  </div>
</div>
<d-toast [value]="msgs" [life]="2000" [styleClass]="'custom-class'" [style]="{ left: '50%',top:'10px' }"></d-toast>
